// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const users = db.collection('users');
  const { type, id, nickname } = event
  let res;
  switch (type) {
    case 'byId':
      res = await users.doc(id).get();
      break;
    case 'byNickname':
      res = await users.where({
        nickname: nickname
      }).get();
      break;
    case 'all':
      res = await users.get();
      break;
    case 'updateById':
      
      break;
  }

  return {
    status: 200,
    message: "成功",
    res: res.data,
  }
}
